import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Partes extends JPanel implements MouseListener,MouseMotionListener
{
	private String imagem;
	private String tipo;
	private int posX;
	private int posY;
	private int origX;
	private int origY;
	private int sizeX;
	private int sizeY;
	private int iniX;
	private int iniY;
	private boolean arrastavel = false;
	private boolean nAcertou = true;
	Mapeamento M;

	public Partes(String img, String tp, int x, int y, int sx, int sy, Mapeamento m)
	{
		imagem = img;
		tipo = tp;
		origX = x;
		origY = y;
		iniX = x ;
		iniY = y;
		posX = x;
		posY = y;
		sizeX = sx;
		sizeY = sy;
		M = m;
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
	}

	public void mouseDragged(MouseEvent e)
	{
		if(arrastavel & nAcertou)
		{
			posX = e.getX() - origX;
			posY = e.getY() - origY;

		}
	}

	public void mouseExited(MouseEvent e)
	{
		arrastavel = false;

	}

	public void mouseMoved(MouseEvent e)
	{

	}

	public void mouseEntered(MouseEvent e)
	{

	}

	public void mouseClicked(MouseEvent e)
	{

	}

	public void mouseReleased(MouseEvent e)
	{
		if (nAcertou){
			colisao();
		}
	}

	public void mousePressed(MouseEvent e)
	{
		int mouseX = e.getX();
		int mouseY = e.getY();

		if(((mouseX >= posX) && (mouseX <= (posX + sizeX)) && ((mouseY >= posY) && (mouseY <= (posY + sizeY)))))
		{
			arrastavel = true;
			origX = mouseX - posX;
			origY = mouseY - posY;

		}
		else
		{
			arrastavel = false;
		}
	}

	public String getImagem()
	{
		return imagem;
	}

	public int getX()
	{
		return posX;
	}

	public int getY()
	{
		return posY;
	}

	public boolean getNAcertou()
	{
		return nAcertou;
	}

	public String getTipo()
	{
		return tipo;
	}
	public void colisao() {

		if ((posX>M.getL1()& posX < M.getL2()) & (posY>M.getH1() & posY<M.getH2())) {
			M.setAcerto();
			posX = M.getXIni();
			posY = M.getYIni();
			nAcertou = false;
		}
		else{
			posX = iniX;
			posY = iniY;
		}
	}
}
